<%-- 
    Document   : SubjectsList
    Created on : 01.03.2012, 14:38:05
    Author     : Alexey Akimov <frinatella@gmail.com>
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.SQLException"%>
<%@page import="student_report.DbConnection"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Subjects List</title>
    </head>
    <body>
        <h1>Subjects List</h1>
        <table border="1"><tr><td>Subject Id</td><td>Subject Name</td></tr>
        <%
         try {
                Connection connection = DbConnection.getConnection();
                ResultSet resultSet = connection.createStatement().executeQuery("select SUBJECT_ID, SUBJECT_NAME from SUBJECTS");
                String href, subjectId, subjectName;
                while (resultSet.next()) {
                    subjectId = resultSet.getString("SUBJECT_ID");
                    subjectName = resultSet.getString("SUBJECT_NAME");
                    href = "href=\"MarksForSubjectsList.jsp?subjectId=" + subjectId + "&subjectName=" + subjectName + "\"";
                    out.println("<tr><td><a " + href + ">" + subjectId + "</a></td>"
                            + "<td><a " + href + ">" + subjectName + "</a></td></tr>");
                }
                } catch (SQLException ex) {
                    out.print("<h3>Subjects list loading failed.</h3>");
                }
        %>
        </table>
    </body>
</html>
